package com.teach.controller.hotel;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.teach.commons.Id;
import com.teach.dto.CommentsSearch;
import com.teach.dto.HotelCommentDTO;
import com.teach.dto.HotelOrderDTO;
import com.teach.dto.HotelRoomInfoDTO;
import com.teach.dto.HotelRoomInfoSearch;
import com.teach.dto.LoginUser;
import com.teach.entity.Comments;
import com.teach.entity.HotelRoomInfo;
import com.teach.entity.HotelRoomOrder;
import com.teach.entity.Shops;
import com.teach.exception.CodeException;
import com.teach.service.CommentsService;
import com.teach.service.FileService;
import com.teach.service.HotelRoomInfoService;
import com.teach.service.HotelRoomOrderService;
import com.teach.service.HotelRoomTypeService;
import com.teach.service.ShopsService;
import com.teach.service.UserService;

@Controller
public class HotelIndexController {

	@Autowired
	private ShopsService service;
	@Autowired
	private UserService userService;
	@Autowired
	private MongoTemplate template;
	@Autowired
	private HotelRoomTypeService service1;
	@Autowired
	private HotelRoomInfoService service2;
	@Autowired
	private HotelRoomOrderService service3;
	@Autowired
	private ShopsService service5;
	@Autowired
	private Id id1;

	@Autowired
	private CommentsService service4;
	@Autowired
	private FileService service6;

	/**
	 * 酒店预定首页
	 * 
	 * @param model
	 * @param shop  店铺
	 * @return
	 */
	@GetMapping("/hotel.html")
	public String doHotel(Model model, Shops shop) {
		Query query = new Query();
		query.addCriteria(Criteria.where("shopTypeId").is(1));
		query.addCriteria(Criteria.where("shopStatus").is(2));
		List<Shops> list = template.find(query, Shops.class);
		Collections.shuffle(list);
		model.addAttribute("list", list);
		List<Shops> list1 = list.subList(0, 3);
		List<Shops> list2 = list.subList(3, 6);
		List<Shops> list3 = list.subList(7, 12);
		model.addAttribute("list1", list1);
		model.addAttribute("list2", list2);
		model.addAttribute("list3", list3);
		return "hotel/index";
	}

	/**
	 * 酒店列表模糊查询
	 * 
	 * @param shop
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/hotel-list.html")
	public String doList(Shops shop, Model model, HttpServletRequest request) {
		Query query = new Query();
		String shopName = request.getParameter("searchHotel");
		Pattern pattern = Pattern.compile("^.*" + shopName + ".*$", Pattern.CASE_INSENSITIVE);
		query.addCriteria(Criteria.where("shopTypeId").is(1));
		query.addCriteria(Criteria.where("shopName").regex(pattern));
		query.addCriteria(Criteria.where("shopStatus").is(2));
		List<Shops> shops = template.find(query, Shops.class);
		model.addAttribute("hotelList", shops);
		return "hotel/hotel-list";
	}

	/**
	 * 酒店房间信息
	 * 
	 * @param id    店铺编号
	 * @param shop
	 * @param model
	 * @return
	 */
	@GetMapping("/hotel-info.html")
	public String doHotelInfo(Long id, Shops shop, Model model) {
		shop = service.get(id);
		String src = "gis-show.html#" + String.valueOf(shop.getPoint().getX()) + "|"
				+ String.valueOf(shop.getPoint().getY()) + "|" + shop.getShopName();
		model.addAttribute("src", src);
		model.addAttribute("list4", shop);
		CommentsSearch search = new CommentsSearch();
		search.setCommentCommentator(id);
		List<Comments> list6 = service4.commentsList1(id);
		if (list6.size() == 0) {
			model.addAttribute("flag", false);
		} else {
			List<HotelCommentDTO> list7 = new ArrayList<HotelCommentDTO>();
			for (int i = 0; i < list6.size(); i++) {
				HotelRoomOrder hro = service3.get(list6.get(i).getCommentId());
				HotelCommentDTO hcd = new HotelCommentDTO();
				hcd.setCommentContent(list6.get(i).getCommentContent());
				hcd.setCommentTime(list6.get(i).getCommentTime());
				hcd.setInTime(hro.getOrderRealStarttime());
				hcd.setUsrName(userService.get(hro.getUserName()).getUserRealName());
				hcd.setRoomName(service1.get(hro.getRoomTypeId()).getRoomTypeName());
				list7.add(hcd);
			}
			model.addAttribute("flag", true);
			model.addAttribute("list6", list7);
		}
		List<HotelRoomInfoDTO> list5 = service2.getRoomInfoDTO(id);
		model.addAttribute("list5", list5);
		return "hotel/hotel-info";
	}

//	/**
//	 * 评价
//	 * @param id商铺id
//	 * @return List<Comments>返回评论集合
//	 */
//	@RequestMapping("/hotel/hotel-info-comments.do")
//	@ResponseBody
//	public Object HotelInfoComment(Long id,Model model) {
//		return service4.commentsPage(search).getList();
//	}

	/**
	 * 取消订单
	 * 
	 * @return
	 */
	@GetMapping("hotel/cancel-order.html")
	public String cancelOrder(Long orderId, Model model, LoginUser user) {
		HotelRoomOrder roomOrder = service3.get(orderId);
		if (roomOrder.getUserName().equals(user.getUserName())) {
			roomOrder.setOrderStatus("已取消");
			service3.update(roomOrder);
		} else {
			throw new CodeException(4006);
		}
		model.addAttribute("type", "取消订单");
		model.addAttribute("num", "2");
		return "hotel/ok";
	}

	/**
	 * 房间订单
	 * 
	 * @param id         店铺编号
	 * @param model
	 * @param roomTypeId 房间类型编号
	 * @param user       登录的用户
	 * @return
	 */
	@GetMapping("/hotel-order.html")
	public String doAdvance(Long id, Model model, Integer roomTypeId, LoginUser user) {
		if (!(user == null)) {
			String roomTypeName = service1.getRoomTypeName(roomTypeId);
			model.addAttribute("roomTypeName", roomTypeName);
			HotelRoomInfo info = service2.getRoomPrice(id, roomTypeId);
			model.addAttribute("roomprice", info);
			Integer typeId = service1.getRoomTypeId(roomTypeName);
			model.addAttribute("typeId", typeId);
			model.addAttribute("shopId", id);
			return "hotel/hotel-dingdan";
		} else {
			return "redirect:login.html";
		}
	}

	/**
	 * 订单评价
	 * 
	 * @return
	 */
	@RequestMapping("hotel/Hotel-Comment.do")
	public String HotelOrderComment(HttpServletRequest request, Model model, Long orderId, String userName,
			Long shopId, String content, LoginUser user) {
		Comments comments = new Comments();
		comments.setCommentId(orderId);
		comments.setCommentUserName(userName);
		comments.setCommentCommentator(shopId);
		comments.setCommentContent(content);
		comments.setCommentType("酒店");
		comments.setCommentIp(request.getRemoteAddr());
//		comments.setCommentScore(score);
		if (user.getUserName().equals(userName)) {
			service4.commentsInsert(comments);
			model.addAttribute("type", "评价");
			model.addAttribute("num", "2");
		} else {
			throw new CodeException(4007);
		}
		return "hotel/ok";
	}

	/**
	 * 房间添加页面
	 * 
	 * @return
	 */
	@GetMapping("hotel/room-add.html")
	public String roomadd() {
		return "hotel/room-add";
	}

	/**
	 * 房间添加
	 * 
	 * @return
	 */
	@PostMapping("hotel/room-add.do")
	public String roomAdd(MultipartFile file, Integer roomId, Integer roomNum, Double roomMarketPrice,
			Double roomPlatformPrice, Integer roomTypeId, String roomIntroduce, Model model, LoginUser user) {
		Long s = service5.getByUserName(user.getUserName()).getId();
		HotelRoomInfo info = new HotelRoomInfo();
		info.setShopId(s);
		info.setRoomIntroduce(roomIntroduce);
		info.setRoomMarketPrice(roomMarketPrice);
		info.setRoomPlatformPrice(roomPlatformPrice);
		info.setRoomTypeId(roomTypeId);
		info.setRoomNum(roomNum);
		info.setRoomImgs(service6.save(file, true));
		try {
			service2.add(info);
			model.addAttribute("type", "添加");
			model.addAttribute("num", "2");
		} catch (Exception e) {
			throw new CodeException(4005);
		}
		System.out.println(file);
		return "hotel/ok";
	}

	/**
	 * 房间信息修改页面
	 * 
	 * @return
	 */
	@GetMapping("hotel/room-Update.html")
	public String roomUpdate(Integer roomId, Model model, LoginUser user) {
		Long s = service5.getByUserName(user.getUserName()).getId();
		HotelRoomInfo info = service2.get(roomId);
		if (s.equals(info.getShopId())) {
			model.addAttribute("roomInfo", info);
		} else {
			throw new CodeException(4003);
		}
		return "hotel/room-Update";
	}

	/**
	 * 房间信息修改
	 * 
	 * @return
	 */
	@PostMapping("hotel/room-Update.do")
	public String doRoomUpdate(MultipartFile file, Integer roomId, Integer roomNum, Double roomMarketPrice,
			Double roomPlatformPrice, Integer roomTypeId, String roomIntroduce, Model model, LoginUser user) {
		Long s = service5.getByUserName(user.getUserName()).getId();
		HotelRoomInfo info = service2.get(roomId);
		info.setRoomIntroduce(roomIntroduce);
		info.setRoomMarketPrice(roomMarketPrice);
		info.setRoomPlatformPrice(roomPlatformPrice);
		info.setRoomTypeId(roomTypeId);
		info.setRoomNum(roomNum);
		if (file != null) {
			info.setRoomImgs(service6.save(file, true));
		}
		if (s.equals(info.getShopId())) {
			try {
				service2.update(info);
			} catch (Exception e) {
				throw new CodeException(4004);
			}
			model.addAttribute("type", "修改");
			model.addAttribute("num", "1");
		} else {
			throw new CodeException(4003);
		}
		return "hotel/ok";
	}

	/**
	 * 支付订单
	 * 
	 * @param shopId         店铺编号
	 * @param model
	 * @param typeId         房间类型编号
	 * @param user           登录的用户
	 * @param orderStartTime 预定日期
	 * @param orderEndTime   离店日期
	 * @param money          开房金额
	 * @return
	 * @throws Exception
	 * 
	 */
	@PostMapping("/hotel-reserve.html")
	public String doReserve(Long shopId, Model model, Integer typeId, LoginUser user, String orderStartTime,
			String orderEndTime, Double money) throws Exception {
		String roomTypeName = service1.getRoomTypeName(typeId);
		model.addAttribute("roomTypeName", roomTypeName);
		// 日期选择判断
		Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse(orderStartTime);
		Date endDate = new SimpleDateFormat("yyyy-MM-dd").parse(orderEndTime);
		String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		Date toDate = new SimpleDateFormat("yyyy-MM-dd").parse(date);
		int date1 = startDate.compareTo(endDate);
		int date2 = startDate.compareTo(toDate);
		int date3 = endDate.compareTo(toDate);
		if (date1 == 1 || date1 == 0) {
			throw new CodeException(4001);
		}
		if (date2 == -1) {
			throw new CodeException(4001);
		}
		if (date3 == -1) {
			throw new CodeException(4001);
		}
		// 添加订单
		try {
			HotelRoomOrder hotelRoomOrder = new HotelRoomOrder();
			hotelRoomOrder.setOrderId(id1.nextId());
			hotelRoomOrder.setOrderCode(id1.nextId());
			hotelRoomOrder.setShopId(shopId);
			hotelRoomOrder.setUserName(user.getUserName());
			hotelRoomOrder.setRoomTypeId(typeId);
			hotelRoomOrder.setOrderStatus("未支付");
			hotelRoomOrder.setOrderCreateTime(new Date());
			hotelRoomOrder.setOrderPreStartdate(new SimpleDateFormat("yyyy-MM-dd").parse(orderStartTime));
			hotelRoomOrder.setOrderPreEnddate(new SimpleDateFormat("yyyy-MM-dd").parse(orderEndTime));
			int day = differentDays(startDate, endDate);
			Double money1 = money * day;
			hotelRoomOrder.setOrderPrice(money1);
			service3.add(hotelRoomOrder);
			model.addAttribute("money", money1);
			model.addAttribute("shopId", shopId);
			model.addAttribute("typeId", typeId);
			model.addAttribute("orderId",hotelRoomOrder.getOrderId());
		} catch (Exception e) {
			throw new CodeException(4000, e);
		}

		// 房型数量判断
		HotelRoomInfo hotelRoomInfo = new HotelRoomInfo();
		int roomNum = service2.getRoomNum(shopId, typeId);
		if (roomNum > 0) {
			roomNum--;
			hotelRoomInfo.setRoomNum(roomNum);
			hotelRoomInfo.setShopId(shopId);
			hotelRoomInfo.setRoomTypeId(typeId);
			service2.updateRoomNum(hotelRoomInfo);
		} else {
			throw new CodeException(4002);
		}
		model.addAttribute("orderStartTime", orderStartTime);
		model.addAttribute("orderEndTime", orderEndTime);
		return "hotel/hotel-reserve";
	}

	
	/**
	 * 支付
	 * @param model
	 * @param req
	 * @param roomTypeName 房间类型名称
	 * @param money 付款金额
	 * @param shopId 店铺编号
	 * @param shop
	 * @param typeId 房间类型编号
	 * @param orderId 订单编号
	 * @return
	 */
	@PostMapping("/hotel-pay.html")
	@Transactional
	public String doHotelPay(Model model, HttpServletRequest req, String roomTypeName, Double money,
			Long shopId, Shops shop, Integer typeId,Long orderId) {
		shop = service.get(shopId);
		HotelRoomInfo info = service2.getByShopIdAndRoomTypeId(shopId, typeId);
		model.addAttribute("q1", orderId.toString());// 订单编号-用于支付传参
		model.addAttribute("q2", money.toString());// 订单价格-用于支付传参
		model.addAttribute("q3", shop.getShopName() + "-" + roomTypeName);// 订单名称-用于支付传参
		model.addAttribute("q4", info.getRoomIntroduce());// 订单描述-订单备注-用于支付传参
		return "hotel/hotel-pay"; //支付跳转
	}
	
	/**
	 * 订单支付
	 * @param model
	 * @param req
	 * @param orderId
	 * @param shop
	 * @return
	 */
	@GetMapping("/hotel-pay1.html")
	@Transactional
	public String doHotelPay1(Model model, HttpServletRequest req,Long orderId,Shops shop) {
		HotelRoomOrder order = service3.get(orderId);
		shop = service.get(order.getShopId());
		HotelRoomInfo info = service2.getByShopIdAndRoomTypeId(shop.getId(), order.getRoomTypeId());
		String roomTypeName = service1.getRoomTypeName(order.getRoomTypeId());
		model.addAttribute("q1", orderId.toString());// 订单编号-用于支付传参
		model.addAttribute("q2", order.getOrderPrice().toString());// 订单价格-用于支付传参
		model.addAttribute("q3", shop.getShopName() + "-" + roomTypeName);// 订单名称-用于支付传参
		model.addAttribute("q4", info.getRoomIntroduce());// 订单描述-订单备注-用于支付传参
		return "hotel/hotel-pay"; //支付跳转
	}
	
	/**
	 * 支付成功后跳转
	 * @param out_trade_no 订单编号
	 * @param trade_no 支付宝返回的支付编号
	 * @return
	 */
	@GetMapping("/hotel-pay-ok.html")
	@Transactional
	public String doHotelPayOk(String out_trade_no,String trade_no) {
			HotelRoomOrder order1 = service3.get(Long.valueOf(out_trade_no));
			order1.setOrderPayTime(new Date());
			order1.setOrderStatus("已支付");
			order1.setOrderPayId(trade_no);
			service3.update(order1);
			return "hotel/pay-ok";//跳转支付
		}
	

	/**
	 * 预定日期和离店日期相差的天数计算
	 * 
	 * @param date1 预定日期
	 * @param date2 离店日期
	 * @return
	 */
	public static int differentDays(Date date1, Date date2) {
		Calendar calendar1 = Calendar.getInstance();
		calendar1.setTime(date1);
		Calendar calendar2 = Calendar.getInstance();
		calendar2.setTime(date2);
		int day1 = calendar1.get(Calendar.DAY_OF_YEAR);
		int day2 = calendar2.get(Calendar.DAY_OF_YEAR);
		int year1 = calendar1.get(Calendar.YEAR);
		int year2 = calendar2.get(Calendar.YEAR);
		if (year1 != year2) // 不同年
		{
			int timeDistance = 0;
			for (int i = year1; i < year2; i++) { // 闰年
				if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
					timeDistance += 366;
				} else { // 不是闰年
					timeDistance += 365;
				}
			}
			return timeDistance + (day2 - day1);
		} else { // 同年
			return day2 - day1;
		}
	}

	/**
	 * 后台管理房间状态
	 * 
	 * @param search
	 * @param model
	 * @param user
	 * @return
	 */
	@RequestMapping("/hotel/room-info.do")
	@ResponseBody
	public Object doList(HotelRoomInfoSearch search, Model model, LoginUser user) {
		Long s = service5.getByUserName(user.getUserName()).getId();
		List<HotelRoomInfoDTO> list5 = service2.getRoomInfoDTO(s);
		if (list5.size() < 5) {
			model.addAttribute("flag", false);
		} else {
			model.addAttribute("flag", true);
		}
		return list5;
	}

	/**
	 * 订单管理
	 * 
	 * @param shop
	 * @return
	 */
	@RequestMapping("/hotel/room-order.do")
	@ResponseBody
	public List<HotelOrderDTO> doOrderList(Shops shop, LoginUser user) {
		Long s = service5.getByUserName(user.getUserName()).getId();
		List<HotelOrderDTO> orderDTOs = service3.listByShopId(s);
		List<HotelOrderDTO> dtos = new ArrayList<>();
		for (int i = 0; i < orderDTOs.size(); i++) {
			shop = service.get(orderDTOs.get(i).getShopId());
			String shopName = shop.getShopName();
			HotelOrderDTO dto = new HotelOrderDTO();
			dto.setOrderId(orderDTOs.get(i).getOrderId());
			dto.setOrderPrice(orderDTOs.get(i).getOrderPrice());
			dto.setOrderStatus(orderDTOs.get(i).getOrderStatus());
			dto.setRoomTypeName(orderDTOs.get(i).getRoomTypeName());
			dto.setShopName(shopName);
			dto.setUserName(orderDTOs.get(i).getUserName());
			dtos.add(dto);
		}
		return dtos;
	}

	/**
	 * 管理订单详情
	 * @return
	 */
	@GetMapping("hotel/viewOrder.html")
	public String doReserve(Long orderId, Model model, LoginUser user) {
		Long s = service5.getByUserName(user.getUserName()).getId();
		HotelRoomOrder order = service3.get(orderId);
		Long shopId = order.getShopId();
		if (shopId.equals(s)) {
			if (order.getOrderStatus().equals("已支付")) {
				model.addAttribute("yfk", true);
			}else if (order.getOrderStatus().equals("已入住")){
				model.addAttribute("yrz", true);
			}else if (service4.get(order.getOrderId())!=null){
				model.addAttribute("order", service4.get(order.getOrderId()));
				model.addAttribute("ypl", true);
			}
			model.addAttribute("roleName", userService.get(order.getUserName()).getUserRealName());
			model.addAttribute("orderInfo", order);
		}else {
			throw new CodeException(4008);
		}
		return "hotel/viewOrder";
	}
	
	
		/**
		 * 入住
		 * @return
		 */
		@PostMapping("hotel/inRoom.do")
		public String inRoom(Long orderId,Long orderCode,Model model, LoginUser user) {
			Long s = service5.getByUserName(user.getUserName()).getId();
			HotelRoomOrder order = service3.get(orderId);
			Long shopId = order.getShopId();
			if (shopId.equals(s)) {
				if (orderCode.equals(order.getOrderCode())) {
					order.setOrderStatus("已入住");
					order.setOrderRealStarttime(new Date());
					service3.update(order);
					model.addAttribute("type", "开房");
					model.addAttribute("num", "2");
				}else {
					throw new CodeException(4010);
				}
			}else {
				throw new CodeException(4009);
			}
			return "hotel/ok";
		}

		/**
		 * 退房
		 * @return
		 */
		@GetMapping("hotel/outRoom.do")
		public String outRoom(Long orderId,Long orderCode,Model model, LoginUser user) {
			Long s = service5.getByUserName(user.getUserName()).getId();
			HotelRoomOrder order = service3.get(orderId);
			Long shopId = order.getShopId();
			if (shopId.equals(s)) {
				order.setOrderStatus("已完成");
				order.setOrderRealEndtime(new Date());
				service3.update(order);
				model.addAttribute("type", "退房");
				model.addAttribute("num", "2");
			}else {
				throw new CodeException(4009);
			}
			return "hotel/ok";
		}
		
		
	/**
	 * 查看我的订单详情
	 * 
	 * @return
	 */
	@GetMapping("hotel/hotel-my-reserve.html")
	public String myReserve(Long orderId, Model model, LoginUser user) {
		HotelRoomOrder order = service3.get(orderId);
		String userName = order.getUserName();
		if (user.getUserName().equals(userName)) {
			if (service4.get(orderId) == null && order.getOrderStatus().equals("已完成")) {
				model.addAttribute("wpj", true);
				model.addAttribute("ywc", true);
			} else if (service4.get(orderId) != null && order.getOrderStatus().equals("已完成")) {
				model.addAttribute("order", service4.get(orderId));
				model.addAttribute("ypj", true);
				model.addAttribute("ywc", true);
			} else if (order.getOrderStatus().equals("未支付")) {
				model.addAttribute("wzf", true);
			} else if (order.getOrderStatus().equals("已支付")) {
				model.addAttribute("yzf", true);
			} else if (order.getOrderStatus().equals("已入住")) {
				model.addAttribute("yrz", true);
			} else if (order.getOrderStatus().equals("已取消")) {
				model.addAttribute("yqx", true);
			}
			model.addAttribute("roleName", user.getUserRealName());
			model.addAttribute("shop", template.findById(order.getShopId(), Shops.class));
			model.addAttribute("orderInfo", order);
		} else {
			throw new CodeException(4006);
		}
		return "hotel/hotel-my-reserve";
	}
	/**
	 * 我的酒店订单 hotel/hotel-my-reserve.html
	 * 
	 * @param shop
	 * @return
	 */
	@RequestMapping("/hotel/my-room-order.do")
	@ResponseBody
	public List<HotelOrderDTO> myOrderDo(Shops shop, LoginUser user) {
		List<HotelOrderDTO> orderDTOs = service3.listByuserName(user.getUserName());
		List<HotelOrderDTO> dtos = new ArrayList<>();
		for (int i = 0; i < orderDTOs.size(); i++) {
			shop = service.get(orderDTOs.get(i).getShopId());
			String shopName = shop.getShopName();
			HotelOrderDTO dto = new HotelOrderDTO();
			dto.setOrderId(orderDTOs.get(i).getOrderId());
			dto.setOrderPrice(orderDTOs.get(i).getOrderPrice());
			dto.setOrderStatus(orderDTOs.get(i).getOrderStatus());
			dto.setRoomTypeName(orderDTOs.get(i).getRoomTypeName());
			dto.setShopName(shopName);
			dto.setUserName(orderDTOs.get(i).getUserName());
			dto.setOrderCreateTime(orderDTOs.get(i).getOrderCreateTime());
			dtos.add(dto);
		}
		return dtos;
	}

	@RequestMapping("/hotel/hotel-info.do")
	@ResponseBody
	public Shops doHotelInfo(Shops shop, LoginUser user) {
		return shop;
	}

	/**
	 * 酒店信息
	 * 
	 * @param model
	 * @param user  登录用户
	 * @param shop
	 * @return
	 */
	@GetMapping("/hotelList.html")
	public String doGetListAll(Model model, LoginUser user, Shops shop) {
		shop = service.getByUserName(user.getUserName());
		String name = service.getType(shop.getShopTypeId()).getShopTypeName();
		model.addAttribute("shopTypeName", name);
		model.addAttribute("shopInfo", shop);
		return "manage/hotel/hotel-list";
	}

	/**
	 * 修改酒店信息
	 * 
	 * @param file    照片上传
	 * @param request
	 * @param user    登录用户
	 * @param shop
	 * @param model
	 * @return
	 */
	@PostMapping("/hotelInfo-update.html")
	public String doUpdateHotelInfo(MultipartFile[] imgs, HttpServletRequest request, LoginUser user, Shops shop,
			Model model) {
		shop = service.getByUserName(user.getUserName());
		String shopName = request.getParameter("shopName");
		String shopMemo = request.getParameter("shopMemo");
		Long id = shop.getId();
		Query query = new Query();
		query.addCriteria(Criteria.where("id").is(id));
		Update update = new Update();
		update.set("shopName", shopName);
		update.set("shopMemo", shopMemo);
		List<String> list = new ArrayList<>();
		if (imgs != null && imgs.length > 0) {
			for (MultipartFile img : imgs) {
				list.add(service6.save(img));
			}
		}
		String[] i = list.toArray(new String[0]);
		update.set("img", i);
		template.findAndModify(query, update, Shops.class);
		model.addAttribute("type", "修改");
		model.addAttribute("num", "1");
		return "hotel/ok";
	}

}
